<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String webpath = request.getContextPath();
	String path = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + webpath + "/";
	request.setAttribute("path", path);
%>
<div class="r_location">
	<i class="r_txtico"></i> 微信配置管理 &gt; 关键词管理&gt;修改关键词
</div>
<form id="add_func_form" method="post" action="cms/wechatkeyword/modify">
	<input type="hidden" id="keywordID" value="${keyWord.id}" />
	<ul class="all_list">
		<li><span class="all_title">推送消息类型:</span><span>
				<select id="message_type" class="ui_input" style="width: 200px;"
					disabled="disabled">
					<option value="text"
						<c:if test="${keyWord.type eq 'text'}">selected="selected"</c:if >>文本</option>
					<option value="news"
						<c:if test="${keyWord.type eq 'news'}">selected="selected"</c:if >>图文</option>
				</select>
			</span>
		 </li>
		<li><span class="all_title">关键词:<font style="color: red;">*</font></span>
			<input class="ui_input" style="width: 200px;" type="text"
			id="keyName" name="keyName" value="${keyWord.keyName}" /> <font
			style="color: red;">*这里填写的渠道要跟生成渠道二维码参数一致</font></li>
		<li>
			<div class="span12 field-box" data-id="text">
				<span class="all_title">文本消息:<font style="color: red;">*</font></span>
				<textarea cols="60" rows="3" id="text">${keyWord.text}</textarea>
			</div>
		</li>
		<li>
			<div class="span12 field-box" data-id="news">
				<span class="all_title">标题:<font style="color: red;">*</font></span>
				<input class="ui_input" style="width: 200px;" type="text" id="Title"
					name="Title" value="${keyWord.title}" />
			</div>
		</li>
		<li>
			<div class="span12 field-box" data-id="news">
				<span class="all_title">描述:<font style="color: red;">*</font></span>
				<input class="ui_input" style="width: 500px;" type="text"
					id="Description" name="Description" value="${keyWord.description}" />
			</div>
		</li>
		<li>
			<div class="span12 field-box" data-id="news">
				<span class="all_title">图片地址:<font style="color: red;">*</font></span>
				<input class="ui_input" style="width: 500px;" type="text"
					id="PicUrl" name="PicUrl" value="${keyWord.picUrl}" />
			</div>
		</li>
		<li>
			<div class="span12 field-box" data-id="news">
				<span class="all_title">图文地址:<font style="color: red;">*</font></span>
				<input class="ui_input" style="width: 500px;" type="text" id="Url"
					name="Url" value="${keyWord.url}" />
			</div>
		</li>
		<li>
			<div class="span12 field-box">
				<span style="color: red;" id="error_message"></span>
			</div>
		</li>
		<li><span class="all_title"></span> <span> <input
				type="button" id="saveConfig" value="修改"
				class="submit_btn m-r15 submitBtn">
		</span></li>
	</ul>
</form>
<script type="text/javascript">
	$(function() {

		// toggle form between inline and normal inputs
		var $buttons = $(".toggle-inputs button");
		var $form = $("form.new_user_form");
		$buttons.click(function() {
			var mode = $(this).data("input");
			$buttons.removeClass("active");
			$(this).addClass("active");

			if (mode === "inline") {
				$form.addClass("inline-input");
			} else {
				$form.removeClass("inline-input");
			}
		});
		$("#message_type").change(function() {
			var message_type = $("#message_type").val();
			if (message_type == "text") {
				$(document).find("div[data-id='news']").css("display", "none");
				$(document).find("div[data-id='text']").css("display", "");
			} else {
				$(document).find("div[data-id='text']").css("display", "none");
				$(document).find("div[data-id='news']").css("display", "");
			}
		});
		$("#message_type").change();
		$("#saveConfig").click(function() {
			var message_type = $("#message_type").val();
			var keyName = $("#keyName").val();
			if (keyName == null || keyName == "") {
				$("#error_message").text('');
				$("#error_message").text("关键词不能为空！");
				return false;
			}
			var type = $("#message_type").val();
			if (type == null || type == "") {
				$("#error_message").text('');
				$("#error_message").text("推送类型不能为空！");
				return false;
			}
			var param = {};
			if (message_type == "text") {
				var text = $("#text").val();
				if (text == null || text == "") {
					$("#error_message").text("");
					$("#error_message").text("文本消息不能为空！");
					return false;
				}
				var id = $("#keywordID").val();
				param = {
					'type' : type,
					'Id' : id,
					'text' : text,
					'keyName' : keyName
				}
			} else {

				var Title = $("#Title").val();
				if (Title == null || Title == "") {
					$("#error_message").text("");
					$("#error_message").text("标题不能为空！");
					return false;
				}
				var Description = $("#Description").val();
				if (Description == null || Description == "") {
					$("#error_message").text("");
					$("#error_message").text("描述不能为空！");
					return false;
				}
				var PicUrl = $("#PicUrl").val();
				if (PicUrl == null || PicUrl == "") {
					$("#error_message").text("");
					$("#error_message").text("图片地址不能不能为空！");
					return false;
				}
				var Url = $("#Url").val();
				if (Url == null || Url == "") {
					$("#error_message").text("");
					$("#error_message").text("图文地址不能不能为空！");
					return false;
				}
				var id = $("#keywordID").val();
				param = {
					'type' : type,
					'Title' : Title,
					'Description' : Description,
					'PicUrl' : PicUrl,
					'Url' : Url,
					'Id' : id,
					'keyName' : keyName
				}
			}
			$.ajax({
				type : "post",
				dataType : 'json',
				async : false,
				url : '${path}cms/wechatkeyword/modify',
				data : param,
				success : function(data) {
					if (data.success == 'succeed') {
						art.dialog({icon: 'succeed',content: data.message,lock:true});
						to_page("/cms/wechatkeyword/view/page");
					} else {
						art.dialog({icon: 'error',content: data.message,lock:true});
					}
				}
			});
			 
		});
	});
</script>
